package com.en.controller.AdminUser;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.en.response.AppException;
import com.en.response.ErrorCodeMsgEnum;
import com.en.model.AdminUser;
import com.en.response.R;
import com.en.service.AdminUserService;
import com.en.utils.JwtToken;
import com.en.utils.ThreadLocalTool;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Description:
 * @Author: wht
 * @Date: 2024-01-16
 */
@Slf4j
@RestController
@RequestMapping("/")
public class AdminUserController {
    @Autowired
    AdminUserService adminUserService;


    // 自己 ---------------------------------------------
    @ApiOperation("登录（通过密码）")
    @PostMapping("/loginByPwd")
    public <T> R<T> loginByPwd(@RequestBody LoginByPwdDto loginDto) {
        AdminUser adminUser = adminUserService.loginByPwd(loginDto);

//        设置token
        String token = JwtToken.getToken(adminUser.getId());
        ThreadLocalTool.setToken(token);

        return R.successMsgData("登录成功！", adminUserService.getResAdminUser(adminUser));
    }

    @ApiOperation("获取token")
    @GetMapping("/getUserInfoByToken")
    public <T> R<T> getUserInfoByToken() {
        AdminUser adminUser = ThreadLocalTool.getUser();
        return R.successData(adminUserService.getResAdminUser(adminUser));
    }


    @ApiOperation("获取腾讯云对象存储的存储桶token")
    @GetMapping("/getCosTempToken")
    public <T> R<T> getCosTempToken() {
        Map res = adminUserService.getCosTempToken();
        return R.successData(res);
    }

}
